<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateVerifyCodeTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('think_verify_code', ['id' => 'id', 'signed' => true, 'primary_key' => 'id', 'auto_increment' => true]);
        $table
            ->addColumn('email', 'string', ['comment' => '邮箱', 'limit' => 100])
            ->addColumn('code', 'string', ['limit' => 6, 'comment' => '验证码'])
            ->addColumn('type', 'integer', ['limit' => 1, 'default' => 0, 'comment' => '验证码类型：0登录注册2修改密码'])
            ->addColumn('expire_time', 'timestamp', ['null' => true, 'comment' => '过期时间'])
            ->addColumn('is_used', 'boolean', ['default' => 0, 'comment' => '是否已使用：0未使用 1已使用'])
            ->addColumn('create_time', 'timestamp', ['null' => true])
            ->addColumn('update_time', 'timestamp', ['null' => true])
            ->addColumn('ip', 'string', [
                'limit' => 45,
                'null' => true,
                'comment' => '发送验证码的IP地址',
                'after' => 'is_used'
            ])
            ->create();
    }
}
